﻿@using Bookify.Web.Services.Auth
@using Bookify.Web.Services.User

@inherits LayoutComponentBase

<MApp>
    <AuthorizeView>
        <Authorized>
            <MAppBar App>
                <MAppBarNavIcon @onclick="() => _drawer = !_drawer"></MAppBarNavIcon>
                <MToolbarTitle>公寓订阅系统</MToolbarTitle>
                <MSpacer></MSpacer>
                <MButton Text Color="primary" Target="_blank" Href="https://docs.masastack.com/blazor/introduction/why-masa-blazor">About</MButton>
                <p>你好, @context.User?.Identity?.Name</p>
                <MButton Text Color="primary" Target="_blank" OnClick="Logout">Logout</MButton>
            </MAppBar>

            <MNavigationDrawer App @bind-Value="_drawer">
                <MList Nav Routable>
                    <MListItem Href="/" ActiveClass="primary--text">
                        <MListItemIcon>
                            <MIcon>mdi-home</MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>Home</MListItemTitle>
                        </MListItemContent>
                    </MListItem>
                    <MListItem Href="/counter" ActiveClass="primary--text">
                        <MListItemIcon>
                            <MIcon>mdi-plus</MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>Counter</MListItemTitle>
                        </MListItemContent>
                    </MListItem>
                    <MListItem Href="/fetchdata" ActiveClass="primary--text">
                        <MListItemIcon>
                            <MIcon>mdi-list-box</MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>Fetch data</MListItemTitle>
                        </MListItemContent>
                    </MListItem>

                    <MListItem Href="/apartment/list" ActiveClass="primary--text">
                        <MListItemIcon>
                            <MIcon>mdi-list-box</MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>公寓列表</MListItemTitle>
                        </MListItemContent>
                    </MListItem>

                    <MListItem Href="/booking/list" ActiveClass="primary--text">
                        <MListItemIcon>
                            <MIcon>mdi-list-box</MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>我的预定</MListItemTitle>
                        </MListItemContent>
                    </MListItem>
                </MList>
            </MNavigationDrawer>

            <MMain>
                <MContainer Fluid>
                    <MErrorHandler>
                        @Body
                    </MErrorHandler>
                </MContainer>
            </MMain>
        </Authorized>
        <NotAuthorized>
            <RedirectToLogin />
        </NotAuthorized>
    </AuthorizeView>
</MApp>

@code {



    [Inject]
    public UserCaller UserCaller { get; set; } = default!;

    private bool? _drawer;

    private async Task Logout()
    {
        await UserCaller.LogoutAsync();

    }

}
